package br.ronei;

import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.InputStreamReader;


public class sandbox {
	private static String arquivo = "c:\\temp\\user.log";
	private int linha = 0;

	public String lerlinha(int ln) {
	        try{
	            // Open the file that is the first 
	            // command line parameter
	            FileInputStream fstream = new FileInputStream(arquivo);
	            // Get the object of DataInputStream
	            DataInputStream in = new DataInputStream(fstream);
                BufferedReader br = new BufferedReader(new InputStreamReader(in));
	            //Read File Line By Line
 	            String str;
                while ((str = br.readLine()) != null)   {
	            	if (linha == ln) {
	            		return "Linha " + Integer.toString(linha) + ", ln " + Integer.toString(ln) + str;
		            } else {
		            	linha++;
		            }
	            }
	            //Close the input stream
	            in.close();

	        	}catch (Exception e){//Catch exception if any
	              System.err.println("Error: " + e.getMessage());
	            }
			return "Acabou o arquivo...";
	}
	public sandbox(String a) {
		super();
		sandbox.arquivo = a;
	}
	public String getArquivo() {
		return arquivo;
	}
	public void setArquivo(String a) {
		arquivo = a;
	}
	public int getTotalLinhasArquivo(){
		int linhas = 0;
        try{
            // Open the file that is the first 
            // command line parameter
            FileInputStream fstream = new FileInputStream(arquivo);
            // Get the object of DataInputStream
            DataInputStream in = new DataInputStream(fstream);
                BufferedReader br = new BufferedReader(new InputStreamReader(in));
            while ((br.readLine()) != null)   {
            	linhas++;
            }
            //Close the input stream
            in.close();
        	}catch (Exception e){//Catch exception if any
              System.err.println("Error: " + e.getMessage());
            }
		
        	return linhas;
	}

}
